package top.xana.acg.anime

import android.app.Application
import android.content.Intent
import android.os.Build
import android.os.Environment
import android.util.Log
import android.widget.Toast
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import dagger.hilt.android.HiltAndroidApp
import dalvik.system.DexClassLoader
import top.xana.acg.anime.utils.LogE
import java.io.File

/**
 * Created by xana on 2022/1/11
 * Describe: hello world
 */
@HiltAndroidApp
class App : Application() {

    companion object {
        const val TAG = "AnimeApp"

        @JvmStatic
        lateinit var app: App

        @JvmStatic
        fun showToast(msg: String) =
            Toast.makeText(app, msg, Toast.LENGTH_SHORT).show()

        @JvmStatic
        fun showToast(msgRes: Int) =
            Toast.makeText(app, msgRes, Toast.LENGTH_SHORT).show()

    }

    override fun onCreate() {
        super.onCreate()
        app = this
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout -> MaterialHeader(this) }
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout -> ClassicsFooter(this) }
        startService()
        loadPlugin()
    }

    private fun loadPlugin() {
        // dexClassLoader.loadClass("top.xana.exp.plugin.TempActivity")
    }


    private fun startService() {
        Log.i(TAG, "MyApplication startService");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(Intent(this, MediaControllerService::class.java))
        } else {
            startService(Intent(this, MediaControllerService::class.java))
        }
    }
}